package com.wolf.controller;

import com.wolf.pojo.Wl_homefloor_style_pc;
import com.wolf.service.Wl_homefloor_style_pcService;
import com.wolf.util.Math;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.swing.*;
import java.util.List;

@Controller
@ComponentScan
public class Wl_homefloor_style_pcController {

    @Autowired
    private Wl_homefloor_style_pcService wl_homefloor_style_pcService;

    public void setWl_homefloor_style_pcService(Wl_homefloor_style_pcService wl_homefloor_style_pcService) {
        this.wl_homefloor_style_pcService = wl_homefloor_style_pcService;
    }

    /**
     * 查询所有
     * @param modelMap
     * @return
     */
    @RequestMapping("wl_homefloor_style_pc_all")
    public String getAll(ModelMap modelMap){

        List<Wl_homefloor_style_pc> list = wl_homefloor_style_pcService.getAll();

        modelMap.addAttribute("wl_homefloor_style_pc_list",list);

        return "table_wl_homefloor_style_pc";
    }

    /**
     * 模糊查询
     * @param modelMap
     * @param cateName
     * @param status
     * @return
     */
    @RequestMapping("wl_homefloor_style_pc_getSelective")
    public String getSelective(ModelMap modelMap,String cateName,String status){

        Integer i = null;

        if(status!=null && status!=""){
            i = Integer.parseInt(status);
        }

        List<Wl_homefloor_style_pc> list = wl_homefloor_style_pcService.getSelective(cateName,i);

        modelMap.addAttribute("wl_homefloor_style_pc_list",list);

        return "table_wl_homefloor_style_pc";

    }

    /**
     *
     * @param flname 分类名称
     * @param lcsx 楼层顺序
     * @param nameid 商品分类对应商品ID列表(以逗号隔开)
     * @return
     */
    @RequestMapping("wl_homefloor_style_pc_insert")
    @ResponseBody
    public String wl_homefloor_style_pc_insert(String flname,Integer lcsx,String nameid){

        Wl_homefloor_style_pc wl = new Wl_homefloor_style_pc();
        //自动生成id
        wl.setId(Math.random());

        wl.setCategoryid(flname);
        wl.setStatus(0);
        wl.setCommodityids(nameid);
        wl.setHomefloorstylesort(lcsx);

        int i = wl_homefloor_style_pcService.insertSelective(wl);

        if(i>0){

            return "1";
        }

        return "0";
    }

    /**
     * 修改状态
     * @param id
     * @param status
     * @return
     */
    @RequestMapping("wl_homefloor_style_pc_updateByStatus")
    public String wl_homefloor_style_pc_updateByStatus(String id,Integer status){

        Wl_homefloor_style_pc wl = new Wl_homefloor_style_pc();

        wl.setId(id);
        if(status==0){
            status=1;
        }else{
            status = 0;
        }
        wl.setStatus(status);

        wl_homefloor_style_pcService.updateByPrimaryKeySelective(wl);

        return "redirect:wl_homefloor_style_pc_all";
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("wl_homefloor_style_pcdelete")
    public String wl_homefloor_style_pcdelete(String id){

        int i = wl_homefloor_style_pcService.deleteByPrimaryKey(id);

        return "redirect:wl_homefloor_style_pc_all";
    }

    /**
     * 修改部分数据
     * @return
     */
    @RequestMapping("wl_homefloor_style_pc_update")
    @ResponseBody
    public int wl_homefloor_style_pc_update(String flname,Integer lcsx,String nameid,String beanid){

        Wl_homefloor_style_pc wl = new Wl_homefloor_style_pc();

        wl.setId(beanid);
        wl.setCategoryid(flname);
        wl.setCommodityids(nameid);
        wl.setHomefloorstylesort(lcsx);
        int i = wl_homefloor_style_pcService.updateByPrimaryKeySelective(wl);
        if(i>0){
            return 1;
        }

        return 0;
    }

    /**
     * 查询单个对象
     * @param modelMap
     * @param id
     * @return
     */
    @RequestMapping("wl_homefloor_style_pc_selectbyprimarykey")
    public String selectByPrimaryKey(HttpServletRequest q,ModelMap modelMap,String id){

        Wl_homefloor_style_pc wl = wl_homefloor_style_pcService.selectByPrimaryKey(id);

        q.getSession().setAttribute("wl_homefloor_style_pc_bean",wl);

        return "redirect:wl_category_getss";
    }

}
